#delimit ;

drop _all;


/* MAKE FIGURE 1 */

set obs 40001;
gen x = 40 + (_n-1)/100;
local mu    = 60;
local sigma = 9;
gen y = exp(-(x - 60)^2/(2*`sigma'^2)) / (2*`sigma'*sqrt(2*_pi));

*gen x = (_n-5000)/2500;
*gen y = normalden(x);
*replace x = x * 10 + 60;

local delta = 2;
local lo1 = 50 - `delta';
local hi1 = 50 + `delta';
local lo2 = 50 - 2*`delta';
local hi2 = 50 + 2*`delta';

keep if x>=40 & x<=80;

twoway (scatter y x, c(l) ms(i) lc(black)) (area y x if x>=`lo1' & x<=50, col(gs10) lc(black)) (area y x if x>=50 & x<=`hi1', col(gs4) lc(black)), 
xtitle("D Vote %") ytitle(Density) legend(off) xlabel(40 `lo1' 50 `hi1' 60 70 80) ylabel(0 .01 .02) yline(0, lc(black)) xline(50, lc(black));

graph export figure1.pdf, replace;


/* twoway (scatter y x, c(l) ms(i) lc(black)) (area y x if x>=`lo2' & x<=`lo1', col(gs11) lc(black)) (area y x if x>=`lo1' & x<=50, col(gs9) lc(black)) (area y x if x>=50 & x<=`hi1', col(gs5) lc(black)) (area y x if x>=`hi1' & x<=`hi2', col(gs3) lc(black)), 
xtitle("D Vote %") ytitle(Density) legend(off) xlabel(40 `lo2' `lo1' 50 `hi1' `hi2' 60 70 80) ylabel(0 .01 .02) yline(0, lc(black)) xline(50, lc(black));

graph export figure3.pdf, replace;
*/


/* MAKE FIGURES 2a and 2b */

drop _all;
set obs 16;
gen sigma = 9;
gen mu = 49 + _n;

foreach i in 1 5 10 20 30 40 50 {;
  local delta = `i'/10;
  gen PD_`i' = 100 * ( normal((50 + `delta' - mu)/sigma) - normal((50 - mu)/sigma) ) / 
                     ( normal((50 + `delta' - mu)/sigma) - normal((50 - `delta' - mu)/sigma) );
  sum PD_`i';
  local PD_`i'_max = _result(6);
};

scatter PD_* mu, ms(o o o o o o o) mc(gs0 gs0 gs0 gs0 gs0 gs0 gs0 gs0) c(l l l l l l l) lc(gs0 gs0 gs0 gs0 gs0 gs0 gs0 gs0) legend(off) ytitle("Prob(D Win)") xscale(range(50 68)) title(sigma = 9, size(medium))
  text(`PD_1_max'  65.25 "delta=0.1%" , place(e))
  text(`PD_5_max'  65.25 "delta=0.5%" , place(e))
  text(`PD_10_max' 65.25 "delta=1.0%" , place(e))
  text(`PD_20_max' 65.25 "delta=2.0%" , place(e))
  text(`PD_30_max' 65.25 "delta=3.0%" , place(e))
  text(`PD_40_max' 65.25 "delta=4.0%" , place(e))
  text(`PD_50_max' 65.25 "delta=5.0% ", place(e));
graph export figure2.pdf, replace;


